package com.lottery.im.module.contact.adapter;

import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseSectionQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lottery.im.R;
import com.lottery.im.module.tim.model.GroupProfile;
import com.lottery.im.module.tim.model.SectionGroupProfile;
import com.lottery.im.util.transformations.CropCircleTransformation;
import java.util.List;

public class GroupListAdapter extends BaseSectionQuickAdapter<SectionGroupProfile, BaseViewHolder> {

  /**
   * Same as QuickAdapter#QuickAdapter(Context,int) but with
   * some initialization data.
   *
   * @param data A new list is created out of this one to avoid mutable list
   */
  public GroupListAdapter(List<SectionGroupProfile> data) {
    super(R.layout.item_grouplist, R.layout.header_grouplist, data);
  }

  @Override protected void convertHead(BaseViewHolder helper, SectionGroupProfile item) {
    helper.setText(R.id.tv_title, item.header);
  }

  @Override protected void convert(BaseViewHolder helper, SectionGroupProfile item) {

    GroupProfile groupProfile = item.t;

    ImageView ivPortrait = helper.getView(R.id.iv_portrait);
    Glide.with(mContext)
        .load(groupProfile.getAvatarUrl())
        .apply(new RequestOptions()
            .bitmapTransform(new CropCircleTransformation())
            .placeholder(R.drawable.icon_conversation_de)
            .error(R.drawable.icon_conversation_de))
        .into(ivPortrait);

    helper.setText(R.id.tv_group_name, groupProfile.getName());
    helper.setText(R.id.tv_num, groupProfile.getMemberNum() + "人");
  }
}
